package zdy.web.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import zdy.web.bean.Group;
import zdy.web.bean.User;

/**
 * Servlet implementation class JstlElServlet
 */
@WebServlet(asyncSupported = true, urlPatterns = { "/s/el" })
public class ElServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ElServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		   //普通字符串
        request.setAttribute("hello", "hello world");
        
        //结构
        Group group=new Group();
        group.setName("提高班八期");
        
        User user=new User();
        user.setName("juyahong");
        user.setAge(25);
        user.setGroup(group);
        request.setAttribute("user", user);
        
        
        //map
        Map map=new HashMap();
        map.put("key1", "value1");
        map.put("key2", "value2");
        request.setAttribute("map", map);
        
        //字符串数组
        String[] strArray=new String[]{"六期","七期","八期","九期","十期"};
        request.setAttribute("str_array", strArray);
        
        
        //对象数组
        User[] users=new User[5];
        for (int i = 0; i < users.length; i++) {
            users[i]=new User();
            users[i].setName("juyahong("+i+")");
        }
        request.setAttribute("users", users);
        
        
        //list
        List groupList=new ArrayList();
        for (int i = 6; i < 12; i++) {
            Group group2=new Group();
            group2.setName("提高班第"+i+"期");
            groupList.add(group2);
        }
        request.setAttribute("groupList", groupList);
        
        
        //empty
        request.setAttribute("tgb6", "");
        request.setAttribute("tgb7", new ArrayList());
        request.setAttribute("tgb8", "提高班第八期");
        request.setAttribute("tgb9", null);
        //request的分发器
        request.getRequestDispatcher("/jsp/day6/el2.jsp").forward(request, response);
        
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	public void destroy() {
		System.out.println("JstlElServlet.销毁！");
		super.destroy();
	}
}
